package com.caiyouxi.advertise.service.impl;

import com.caiyouxi.advertise.mapper.SeatMapper;
import com.caiyouxi.advertise.model.Seat;
import com.caiyouxi.advertise.service.SeatService;
import com.caiyouxi.common.Constant;
import com.caiyouxi.common.bean.QueryParams;
import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.exception.ErrorCode;
import com.caiyouxi.common.service.BaseService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SeatServiceImpl extends BaseService implements SeatService {

    private Logger logger = Logger.getLogger(SeatServiceImpl.class);

    @Autowired
    SeatMapper seatMapper;

    /**
     * 查询所有位置
     */
    @Override
    public ResData get_all(Seat bean) {
        return success(seatMapper.get_all(bean));
    }

    /**
     * 查询游戏主题列表
     * @param bean
     * @return
     */
    @Override
    public ResData get_list(Seat bean) {
        Integer reids_page_size = Integer.parseInt( redisService.get("sys.pagesize").toString());
        if(null != reids_page_size){
            bean.setPage_size(reids_page_size);
        }
        if(null != bean.getPage_no()){
            bean.setPage(bean.getPage_no());
        }
        bean.setPage_size(2);
        QueryParams pageList = new QueryParams();
        pageList.setList(seatMapper.get_list(bean));
        pageList.setTotal(seatMapper.total_count(bean));
        pageList.setPage(bean.getPage());
        return success(pageList);
    }

    /**
     * 添加位置
     */
    @Override
    public ResData add_seat(Seat bean) {
        int result = seatMapper.insert(bean);
        if(result == 1){
            return success(null);
        }else{
            return failed(ErrorCode.SYS_BUSSINESS_ERROR.getCode(),ErrorCode.SYS_BUSSINESS_ERROR.getMsg(),null);
        }
    }

    /**
     *删除位置
     */
    @Override
    public ResData delete_seat(Seat bean) {
        bean.setIs_delete(Constant.DELETED);
        int result =  seatMapper.update(bean);
        if(result == 1){
            return success(null);
        }else{
            return failed(ErrorCode.SYS_BUSSINESS_ERROR.getCode(),ErrorCode.SYS_BUSSINESS_ERROR.getMsg(),null);
        }
    }

    /**
     * 获取游戏主题详情
     * @param bean
     * @return
     */
    @Override
    public ResData get_info(Seat bean) {
        return success(seatMapper.get_by_id(bean.getId()));
    }

    /**
     * 更新、排序 、状态
     * @param bean
     * @return
     */
    @Override
    public ResData update(Seat bean) {
        int result =  seatMapper.update(bean);
        if(result == 1){
            return success(null);
        }else{
            return failed(ErrorCode.SYS_BUSSINESS_ERROR.getCode(),ErrorCode.SYS_BUSSINESS_ERROR.getMsg(),null);
        }
    }
}
